package com.jf.cloud.product.listener;

import com.jf.cloud.api.order.bo.DeleteShopCartItemMessageBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.product.service.ShopCartService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 解锁库存的监听
 *
 * @author zz
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.DELETE_SHOP_CART_ITEM_TOPIC, consumerGroup = RocketMqConstant.DELETE_SHOP_CART_ITEM_TOPIC)
public class DeleteShopCartItemConsumer implements RocketMQListener<DeleteShopCartItemMessageBO> {
    private static final Logger LOGGER = LoggerFactory.getLogger(DeleteShopCartItemConsumer.class);

    @Autowired
    private ShopCartService shopCartService;

    /**
     * 删除购物车商品
     */
    @Override
    public void onMessage(DeleteShopCartItemMessageBO deleteShopCartItemMessageBO) {
        LOGGER.info("提交订单，删除购物车商品.....{}", deleteShopCartItemMessageBO);
        shopCartService.deleteShopCartItemsByShopCartItemIds(deleteShopCartItemMessageBO.getUserId(), deleteShopCartItemMessageBO.getShopCartItemIds());
    }
}
